import 'package:basic/Tabs/mine.dart';
import 'package:flutter/material.dart';
import 'Tabs/mine.dart';
import 'tabs/first_page.dart';
import 'main.dart';
import 'package:shared_preferences/shared_preferences.dart';

class MainPage extends StatefulWidget {
  Map arguments;

  MainPage({Key key, this.arguments}) {
    if (arguments == null) {
      SharedPreferences prefs = SpUtil.prefs;
      arguments = {
        "id": prefs.getInt("id"),
        "username": prefs.getString("username")
      };
    }
  }

  _TabsState createState() => _TabsState(this.arguments);
}

class _TabsState extends State<MainPage> {
  final Map arguments;
  int _currentIndex = 0;
  List _pageList; // = [FirstPage(argument: arguments), MinePage()];

  _TabsState(this.arguments) {
    print('收到参数');
    //print(arguments['username']);
    this._pageList = _pageList = [
      FirstPage(arguments: arguments),
      MinePage(arguments: arguments)
    ];
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: this._pageList[this._currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: this._currentIndex, //配置对应的索引值选中
        onTap: (int index) {
          setState(() {
            //改变状态
            this._currentIndex = index;
          });
        },
        iconSize: 36.0, //icon的大小
        fixedColor: Colors.blue, //选中的颜色
        type: BottomNavigationBarType.fixed, //配置底部tabs可以有多个按钮
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.home), label: "首页"),
          BottomNavigationBarItem(icon: Icon(Icons.person), label: "个人中心")
        ],
      ),
    );
  }
}
